// linux/devres.c   
/**
 * devm_kmalloc - Resource-managed kmalloc
 * @dev: Device to allocate memory for
 * @size: Allocation size
 * @gfp: Allocation gfp flags
 *
 * Managed kmalloc.  Memory allocated with this function is
 * automatically freed on driver detach.  Like all other devres
 * resources, guaranteed alignment is unsigned long long.
 *
 * RETURNS:
 * Pointer to allocated memory on success, NULL on failure.
 */
void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
{
  struct devres *dr;

  /* use raw alloc_dr for kmalloc caller tracing */
  dr = alloc_dr(devm_kmalloc_release, size, gfp);
  if (unlikely(!dr))
    return NULL;

  /*
   * This is named devm_kzalloc_release for historical reasons
   * The initial implementation did not support kmalloc, only kzalloc
   */
  set_node_dbginfo(&dr->node, "devm_kzalloc_release", size);
  devres_add(dev, dr->data);
  return dr->data;
}
EXPORT_SYMBOL_GPL(devm_kmalloc);




/* 
函数devm_kzalloc（）和kzalloc（）一样都是内核内存分配函数，但是devm_kzalloc（）是跟设备（装置）有关的，当设备（装置）被拆卸或者驱动（驱动程序）卸载（空载）时，内存会被自动释放。另外，当内存不在使用时，可以使用函数devm_kfree（）释放。
而kzalloc（）则需要手动释放（使用kfree（）），但如果工程师检查不仔细，则有可能造成内存泄漏。
*/
